import BaseUtil from '@/BaseUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
import GameMonsters from 'code/Scripts/GameMonster';
/**
 * 冥火暴击
 **/
export default class BossSpell_MingHuoBaoJi extends AbilityBase {
    static instance: BossSpell_MingHuoBaoJi;
    constructor(id: string = 'Mkl4') {
        super(id);
        BossSpell_MingHuoBaoJi.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        target = SelectUtil.getRandomEnemyInRange(source, 1000);
        let x = GetUnitX(target);
        let y = GetUnitY(target);
        let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, x, y);
        BossAbilityManagerInstance.text('冥火暴击', source);
        BaseUtil.runLater(1, () => {
            let angle = MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), x, y);
            MovementCommon.LineMissile({
                missile: '3588.mdx',
                angle: angle,
                speed: 450,
                distance: 1000,
                radius: 50,
                caster: source,
                onHit: this.onHit.bind(this),
                onFinish: this.finish.bind(this),
                other: mark,
            });
            mark = null;
            source = null;
        });
    }
    finish(p: LineMissileConfig) {
        DestroyEffect(p.other);
    }
    onHit(p: LineMissileConfig, hit: unit) {
        DamageSystemInstance.applyFireDamage(hit, p.caster, 600);
        DamageSystemInstance.applyAttachAttackDamage(hit, p.caster, UnitCommon.取攻击(p.caster));
        StunSystemIntance.stun(hit, 2, p.caster);
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageCaster.mdl', hit, 'overheader'));
        GameMonsters.create('nsoc', p.curX, p.curY);
        DestroyEffect(p.other);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
